<?php

$screen = get_current_screen();
$id = get_the_ID();
if ( $screen->post_type == 'post' )
{
	// wp_nonce_field("custompost_action", "custompost_nonce");
	$aData = get_post_meta($id, "custompost", true);
	
	$aHeaderType = array('imagestatic'=>'Image Static', 'imageslideshow'=>'Image Slideshow', 'youtube'=>'Youtube');
	$checked = isset($aData['headertype']) && !empty($aData['headertype']) ? $aData['headertype'] : 'imagestatic';
	?>
	<div>
		<div>
			<div class="postbox">
				<div class="handlediv" title="Click to toggle"><br></div>
				<h3 class="hndle"><span>Header</span></h3>
				<div class="inside">
					<table class="form-table">
						<tr>
							<th scope="row">
								Header Type
							</th>
							<th>
								<div class="inside">
									<?php 
									foreach ($aHeaderType as $k => $v) :
										?>
										<label for="<?php echo $k ?>">
											<input id="<?php echo $k ?>"  class="headertype" type="radio" name="custompost[headertype]" value="<?php echo $k ?>" <?php echo $k == $checked ? 'checked' : ''; ?>>
											<?php echo $v ?>
										</label>
										<br>
										<?php 
									endforeach;
									?>
								</div>
							</th>
						</tr>

						<tr class="zone-of-staticimg">
							<th scope="row">	
								Upload an image 
							</th>
							<td> 
								<a class="photo blog-img" href="#">
									<?php if (isset($aData['staticimg']) && !empty($aData['staticimg'])) : 
										  	echo wp_get_attachment_image($aData['staticimg']);
										else :
									?>
									<img src="<?php echo isset($aData['staticimg']) && !empty($aData['staticimg']) ?  $aData['staticimg'] : QVA_ADMIN_IMG . 'no-img.jpg' ?>">
									<?php endif; ?>
								</a>
								<input id="staticimg" class="input-photo" type="hidden" size="70" value="<?php echo isset($aData['staticimg']) && !empty($aData['staticimg']) ? $aData['staticimg'] : ''; ?>" name="custompost[staticimg]">
							</td>
						</tr>

						<tr class="zone-of-slideshow">
							<th>
								Upload images
							</th>
							<td>
								<div class="controls wrap-upload">
									<input id="slideshow" class="input-photo img-id box-image-id" type="text" size="70" value="<?php echo isset($aData['slideshow']) && !empty($aData['slideshow']) ? $aData['slideshow'] : ''; ?>" name="custompost[slideshow]" >
									<input type="button" class="blue-btn btn btn-info upload-image multiple_upload multiple_upload" value="Upload Images">
								</div>
								<ul class="lux-gallery posttype-post textalign-left">
									<?php 

										if (isset($aData['slideshow']) && !empty($aData['slideshow']))
										{
											$aId = explode(",", $aData['slideshow']);
											foreach ($aId as $id) {
												echo '<li class="attachment img-item width-300" data-id="'.$id.'">';
												echo wp_get_attachment_image($id, 'thumbnail');
												?>
												<a class="md-remove" href="#">
													<i class="fa fa-times"></i>
												</a>
												</li>
												<?php 
											}
										}
									?>
								</ul>
							</td>
						</tr>

						<tr class="zone-of-youtube">
							<th>
								Video - Youtube/Vimeo
							</th>
							<td>
								<!-- <a class="photo blog-img" href="#" style="margin-bottom: 10px">
									<?php if(isset($aData['youtubeposter']) && !empty($aData['youtubeposter'])) :  
											echo wp_get_attachment_image($aData['youtubeposter']);
										else :
									?>
									<img src="<?php echo isset($aData['youtubeposter']) && !empty($aData['youtubeposter']) ?  $aData['youtubeposter'] : QVA_ADMIN_IMG . 'no-img.jpg' ?>">
									<?php endif; ?>
								</a> -->
								<!-- <input id="staticimg" class="input-photo" type="hidden" size="70"  name="custompost[youtubeposter]" value="<?php echo isset($aData['youtubeposter']) && !empty($aData['youtubeposter']) ? esc_url($aData['youtubeposter']) : ''; ?>">
								<br> -->

								<input class="wiloke_input" type="text" placeholder="Video Link" type="text" name="custompost[videolink]" value="<?php echo isset($aData['videolink']) && !empty($aData['videolink']) ? esc_url($aData['videolink']) : ''; ?>">
								<p class="help">Enter Youtube like this : https://www.youtube.com/watch?v=dOD_DnxikWs  or Vimeo Link like this: http://vimeo.com/25708134<br>
								</p>
							</td>
						</tr>

					</table>
				</div>
			</div>
		</div>
	</div>	
	<?php 
}